package org.geoserver.jtilecache.service;

import java.io.IOException;
import java.net.URLConnection;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class Connection {
	private static Log log = LogFactory.getLog(org.geoserver.jtilecache.service.Connection.class);

	private Request request = null;
	private URLConnection outgoing_request = null;

	public Connection(Request request) {
		this.setRequest(request);
	}

	public void connect() throws IOException {
		try {
			outgoing_request = request.getURL().openConnection();
		} catch(IOException ioe) {
			log.error("Failed to connect to " + request.toString() + " : ", ioe);
		}
	}

	/**
	 * @return the request
	 */
	public Request getRequest() {
		return request;
	}

	/**
	 * @param request the request to set
	 */
	public void setRequest(Request request) {
		this.request = request;
	}

	/**
	 * @return the Response for this connection
	 */
	public Response getResponse() {
		return new Response(outgoing_request);
	}

}
